/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dbf;

import com.linuxense.javadbf.DBFException;
import com.linuxense.javadbf.DBFField;
import com.linuxense.javadbf.DBFReader;
//import com.mysql.jdbc.Connection;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import koneksi.Koneksi;

/**
 *
 * @author rosi
 */
public class OpenSelect {

    String fileName = "E:\\rosi\\kanisius\\ARSIP\\0002FEB\\INV10202.dbf";
    ArrayList<Object> kolom = new ArrayList<Object>();

    public void bacaFile() throws FileNotFoundException, IOException {

//        try {
        Connection conn = null;
//        DBFField field = null;
        try {
            conn = Koneksi.open();
            Statement st = conn.createStatement();
            
            FileInputStream inputStream = new FileInputStream(fileName);
            DBFReader reader = new DBFReader(inputStream);

            String query = "select PROD_ID from " + fileName + " ";
            ResultSet res = st.executeQuery(query);

            //baca nama kolom
//            int jmlKolom = reader.getFieldCount();
//            for (int i = 0; i < jmlKolom; i++) {
//
//                DBFField field = reader.getField(i);
//                System.out.print(field.getName() + "\t");
//                kolom.add(field.getName());
//            }
//            System.out.println("\n");

            //baca isi kolom
            Object[] rowObjects;
//            while ((rowObjects = reader.nextRecord()) != null) {
            while (res.next()) {
                rowObjects = reader.nextRecord();
//                for (int i = 0; i < rowObjects.length; i++) {
                for (int i = 0; i <= res.getMetaData().getColumnCount(); i++) {
                    System.out.println(rowObjects[i].toString() + " ");
                }
//                System.out.println();
            }

            inputStream.close();
        } catch (SQLException ex) {
            Logger.getLogger(QueryDBF.class.getName()).log(Level.SEVERE, null, ex);
        } catch (DBFException e) {
            System.out.println(e.getMessage());
        }
    }
}
